package com.erdos.core.dao.ibatis;

import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;

import com.erdos.common.dao.DaoBase;
import com.erdos.common.dao.IBatisGenericDaoImpl;
import com.erdos.common.exception.DaoException;
import com.erdos.common.pagination.LimitSqlExecutor;
import com.erdos.common.pagination.Page;
import com.erdos.common.web.LoginUtil;
import com.erdos.core.dao.AttributeValueDao;
import com.erdos.core.entity.AttributeValue;
import com.erdos.core.entity.AttributeValueVO;
public class AttributeValueDaoImpl extends IBatisGenericDaoImpl<AttributeValue>
		implements AttributeValueDao {
	@SuppressWarnings("unchecked")
	public Page<AttributeValueVO> findAttributeValueVOByPage(
			Map<String, Object> params, int pageNo, int limit) {
		params.put(DaoBase.GLOBAL_FACILITY_KEY, LoginUtil.getFacilityIds());
		Page<AttributeValueVO> page = new Page<AttributeValueVO>();
		page.setPageNo(pageNo);
		page.setLimit(limit);
		String findSqlMapId = "AttributeValue.findAttributeValueVO";
		// logger.debug("findSqlMapId=" + findSqlMapId);
		try {
			List<AttributeValueVO> resultList = getSqlMapClientTemplate()
					.queryForList(findSqlMapId, params, page.getOffset(), limit);
			page.setResultList(resultList);
		} catch (DataAccessException e) {
			throw new DaoException("jdbc.error.code.Common.findByPage",
					new String[] { entityClass.getName() }, e);
		}
		page.setTotalRows(((LimitSqlExecutor) getSqlExecutor())
				.getTotalRowsCount());
		return page;
	}
}
